import _ from "lodash";
export function getRandomItems(arr: any, sum: number | string) {
  if (typeof sum === "string") {
    const sumText = sum.split("-");
    sum = _.random(
      sumText[0] as unknown as number,
      sumText[1] as unknown as number
    );
  }
  const newArr = [...arr];
  const result: any[] = [];
  for (let i = 0; i < sum; i++) {
    const randomIndex = _.random(0, newArr.length - 1);
    const value = newArr.splice(randomIndex, 1)[0];
    result.push(value);
  }
  return result;
}

export function backTimeout(ms: number) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}
